package com.h3c.nem.mapstruct;

import com.h3c.nem.bo.TbOfferWorkerBO;
import com.h3c.nem.dto.OfferAdjustDTO;
import com.h3c.nem.dto.TbOfferWorkerDTO;
import com.h3c.nem.dto.sap.SubmitFormalWorkerIdDTO;
import com.h3c.nem.entity.TbOfferModify;
import com.h3c.nem.entity.TbOfferWorker;
import com.h3c.nem.vo.InsuredCityVO;
import com.h3c.nem.vo.TbOfferWorkerVO;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
import org.mapstruct.factory.Mappers;

import java.util.List;
import java.util.Objects;

/**
 * @author chenyifan
 * @date 2022/6/2 16:01
 */
@Mapper
public interface TbOfferWorkerMapstruct {

    TbOfferWorkerMapstruct INSTANCE = Mappers.getMapper(TbOfferWorkerMapstruct.class);

    /**
     * 实体类转成VO
     * @param offerWorker
     * @return
     */
    TbOfferWorkerVO entity2VO(TbOfferWorker offerWorker);

    /**
     * DTO转成实体类
     * @param workerDTO
     * @return
     */
    TbOfferWorker dto2Entity(TbOfferWorkerDTO workerDTO);

    /**
     * 实体类toBO
     * @param offerWorker
     * @return
     */
    @Mapping(source = "birthday", target = "birthday", dateFormat = "yyyy年MM月dd日")
    @Mapping(source = "addPartyDate", target = "addPartyDate", dateFormat = "yyyy年MM月dd日")
    @Mapping(source = "firstWorkDate", target = "firstWorkDate", dateFormat = "yyyy年MM月dd日")
    @Mapping(source = "marriageDate", target = "marriageDate", dateFormat = "yyyy年MM月dd日")
    @Mapping(source = "competitionSignDate", target = "competitionSignDate", dateFormat = "yyyy年MM月dd日")
    @Mapping(source = "lastLeaveDate", target = "lastLeaveDate", dateFormat = "yyyy年MM月dd日")
    @Mapping(source = "contractBeginDate", target = "contractBeginDate", dateFormat = "yyyy年MM月dd日")
    @Mapping(source = "contractEndDate", target = "contractEndDate", dateFormat = "yyyy年MM月dd日")
    @Mapping(source = "applyReportDate", target = "applyReportDate", dateFormat = "yyyy年MM月dd日")
    @Mapping(source = "planReportDate", target = "planReportDate", dateFormat = "yyyy年MM月dd日")
    @Mapping(source = "offerDate", target = "offerDate", dateFormat = "yyyy年MM月dd日")
    @Mapping(source = "joinDate", target = "joinDate", dateFormat = "yyyy年MM月dd日")
    @Mapping(source = "updateTime", target = "updateTime", dateFormat = "yyyy年MM月dd日")
    @Mapping(source = "offlineTime", target = "offlineTime", dateFormat = "yyyy年MM月dd日")
    @Mapping(source = "certType.name", target = "certType")
    TbOfferWorkerBO entity2BO(TbOfferWorker offerWorker);

    /**
     * entity转dto
     * @param worker
     * @return
     */
    TbOfferWorkerDTO entityToDto(TbOfferWorker worker);

    /**
     * offer调整
     * @param worker
     * @return
     */
    @Mapping(source ="afterDeptName",target ="deptNameChain")
    @Mapping(source ="afterPostId",target ="postId")
    @Mapping(source ="afterPostName",target ="postName")
    OfferAdjustDTO entityToAdjustDto(TbOfferModify worker);

    /**
     * entity转dto
     * @param worker
     * @return
     */
    List<TbOfferWorkerDTO> entityToDto(List<TbOfferWorker> worker);

    /**
     * 转换成参保地VO
     * @param worker
     * @return
     */
    List<InsuredCityVO> dtoToInsuredCity(List<TbOfferWorkerDTO> worker);

    /**
     * 正式工号生成数据转换
     * @param worker
     * @return
     */
    TbOfferWorker submitDtoToEntity(SubmitFormalWorkerIdDTO worker);

    /**
     * 填充属性
     * @param offerWorkerBO
     */
    @AfterMapping
    default void afterEntity2BO(@MappingTarget TbOfferWorkerBO offerWorkerBO){
        if (Objects.isNull(offerWorkerBO.getProbationMonth()) || offerWorkerBO.getProbationMonth() == 0) {
            offerWorkerBO.setTypeOfTrialPeriod("A");
        } else {
            offerWorkerBO.setTypeOfTrialPeriod("B");
        }
    }
}
